package com.fzz.learning_forum.serviceImpl;

import com.fzz.learning_forum.dao.ArticleMapping;
import com.fzz.learning_forum.domain.Article;
import com.fzz.learning_forum.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapping articleMapping;

    //分页查询文章
    @Override
    public PageInfo<Article> selectArticleWithPage(Integer page, Integer count) {

        PageHelper.startPage(page,count);
        List<Article> articleList = articleMapping.selectArticleWithPage();
        PageInfo<Article> pageInfo=new PageInfo<>(articleList);
        return pageInfo;
    }

    //根据id查询文章
    @Override
    public PageInfo<Article> selectArticleWithPageById(Integer page, Integer count, Integer id) {
        PageHelper.startPage(page,count);
        List<Article> articleList = articleMapping.selectArticleWithPageById(id);
        PageInfo<Article> pageInfo=new PageInfo<>(articleList);
        return pageInfo;
    }
    //根据tags模糊查询文章
    @Override
    public PageInfo<Article> selectArticleByTags(Integer page, Integer count, String tags) {
        PageHelper.startPage(page,count);
        List<Article> articleList = articleMapping.selectArticleByTags(tags);
        PageInfo<Article> pageInfo=new PageInfo<>(articleList);
        return pageInfo;
    }
}
